home *** CD-ROM | disk | FTP | other *** search
- #ifndef __TOOLBOXEVENT__
- #define __TOOLBOXEVENT__
- #pragma once
-
- #include <Events.h>
-
- enum EventClass
- {
- kEvtUnknown,
- kEvtIdle, // null
- kEvtMouse, // mouseDown/mouseUp/mouseMoved
- kEvtKeyboard, // keyDown/keyUp/autoKey
- kEvtDisk, // diskEvt
- kEvtUpdate, // updateEvt
- kEvtActivate, // activate/resume
- kEvtDectivate, // deactivate/suspend
- kEvtHighLevel
- };
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=mac68k
- #elif PRAGMA_STRUCT_PACKPUSH
- #pragma pack(push, 2)
- #elif PRAGMA_STRUCT_PACK
- #pragma pack(2)
- #endif
-
- struct KeyEvtMessage
- {
- Byte filler;
- Byte adbAddr;
- Byte keyCode;
- Byte chrCode;
- };
-
- struct OSEvtMessage
- {
- Byte message;
- Byte filler1;
- Byte filler2;
- bool filler3 : 6;
- bool convertClip : 1;
- bool resumeFlag : 1;
- };
-
- struct EvtModifierBits
- {
- bool rightControlKey : 1;
- bool rightOptionKey : 1;
- bool rightShiftKey : 1;
- bool controlKey : 1;
-
- bool optionKey : 1;
- bool alphaLock : 1;
- bool shiftKey : 1;
- bool cmdKey : 1;
-
- bool btnState : 1;
- bool filler : 6;
- bool activeFlag : 1;
- };
-
- union EvtMessage
- {
- KeyEvtMessage key;
- OSEvtMessage os;
- WindowPtr win;
- long data;
- };
-
- union EvtModifiers
- {
- EvtModifierBits bits;
- short data;
- };
-
- class ToolboxEvent
- {
- protected:
- short type;
- short what;
- EvtMessage message;
- UInt32 when;
- Point where;
- EvtModifiers modifiers;
- short part;
- WindowPtr window;
-
- public:
- ToolboxEvent();
- ToolboxEvent(const EventRecord& event);
-
- void ParseEvent();
-
- inline long GetEventTime() { return when; }
- inline EventKind GetEventKind() { return what; }
- inline WindowPtr GetWindow() { return window; }
- inline short GetPartCode() { return part; }
-
- inline const Point& GetMousePosition() const { return where; }
- inline const EvtModifierBits& GetModifierBits() const { return modifiers.bits; }
-
- inline bool CmdKeyDown() { return modifiers.bits.cmdKey; }
-
- inline Byte GetCharCode() { return message.key.chrCode; }
- inline Byte GetKeyCode() { return message.key.keyCode; }
- inline Byte GetADBAddr() { return message.key.adbAddr; }
-
- inline bool IsNullEvent() { return what == nullEvent; }
- inline bool IsHighLevelEvent() { return what == kHighLevelEvent; }
-
- inline void SetToNullEvent() { type = kEvtIdle; what = nullEvent; }
-
- inline operator EventRecord*() { return (EventRecord*) &what; }
- };
-
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=reset
- #elif PRAGMA_STRUCT_PACKPUSH
- #pragma pack(pop)
- #elif PRAGMA_STRUCT_PACK
- #pragma pack()
- #endif
-
- #endif __TOOLBOXEVENT__